# -*- coding: utf-8 -*-
"""
Date: 2021-12-13
Author: J z
"""
from app.user.areaservice import action_register
from framework.firefly_dc.base_action import AuthLogAction
from framework.firefly_dc.global_errcode import GlobalErrCode


@action_register(action_id=10001)
class Login(AuthLogAction):
    """登录"""

    def parse_arguments(self):
        return self.get_str('Mobile') and self.get_str('Password')

    def take_action(self):
        res = self.cc.auth.login(self.Mobile, self.Password)
        self.add_response_dict(res)
        return True


@action_register(action_id=10002)
class RefreshToken(AuthLogAction):
    """刷新Jwt"""

    def parse_arguments(self):
        return self.get_str('RefreshToken')

    def take_action(self):
        res, token_status = self.cc.auth.refresh_token(self.RefreshToken)
        if token_status == GlobalErrCode.Token_ERROR:
            self.set_error(stat=GlobalErrCode.Token_ERROR)
        self.add_response_dict(res)
        return True


@action_register(action_id=10003)
class Register(AuthLogAction):
    """注册"""

    def parse_arguments(self):
        return self.get_str('Mobile') and self.get_str('Password')

    def take_action(self):
        res = self.cc.auth.register(self.Mobile, self.Password)
        self.add_response_dict(res)
        return True
